﻿using System.Collections;
using System.Web;
using Bricks.Caching;

namespace Motar.Web.Caching
{
    
    /// <summary>
    /// 
    /// </summary>
    public class HttpRequestCacheFacade : CacheFacadeBase<IDictionary>, IHttpRequestCacheFacade
    {

        /// <summary>
        /// 
        /// </summary>
        public HttpRequestCacheFacade() :
            base(() => HttpContext.Current.Items)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public override void Add(string key, object value)
        {
            Execute(items => items.Add(key, value));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public override bool Contains(string key)
        {
            return Execute<bool>(items => items.Contains(key));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public override object Get(string key)
        {
            return Execute<object>(items => items[key]);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        public override void Remove(string key)
        {
            Execute(items => items.Remove(key));
        }

        /// <summary>
        /// 
        /// </summary>
        public override void Flush()
        {
            Execute(items => items.Clear());
        }
    }
}
